package com.repair.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.repair.entity.model.ReminderRecord;
import com.repair.entity.model.User;
import com.repair.service.ReminderRecordService;
import com.repair.service.UserService;
import com.repair.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户账户：用于保存用户登录信息 前端控制器
 * </p>
 *
 * @author tianwenle
 * @since 2023-04-12
 */
@RestController
@RequestMapping("/user/admin")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private ReminderRecordService reminderRecordService;

    @GetMapping("/getAll")
    public R getAll() {

        // 查询全部
        List<User> list = userService.list();
        System.out.println("查询全部list = " + list);
        // 按照id查询
        User user = userService.getById(5);
        System.out.println("按照id查询user = " + user);
        // 根据id删除
//        userService.removeById();
//        userService.saveOrUpdate(new User())

//        userService
        int count = userService.count();

        QueryWrapper<User> wrapper = new QueryWrapper<>();

        wrapper.eq("state",1);
        // select * from user where state = 1
//
//        User one = userService.getOne(wrapper);

        List<User> userList = userService.list(wrapper);


        // 分页查询
        Page<User> page = new Page<>(1,1);
        userService.page(page);


        long total = page.getTotal();
        List<User> records = page.getRecords();

        return R.ok().data("list", list);

    }

}

